package hankz.spring.aop.aspectj;

import hankz.spring.aop.Pointcut;
import hankz.spring.aop.PointcutAdvisor;
import org.aopalliance.aop.Advice;

/**
 * @auther zzc
 * @date 2021 11 29
 * <p>
 * AspectJExpressionPointcutAdvisor 实现了 PointcutAdvisor 接口，把切面 pointcut、拦截方法 advice 和具体的拦截表达式包装在一起。
 * z这样就可以在 xml 的配置中定义一个 pointcutAdvisor 切面拦截器了
 */
public class AspectJExpressionPointcutAdvisor implements PointcutAdvisor {

    //切面
    private AspectJExperssionPointcut pointcut;

    //具体的拦截方法
    private Advice advice;

    //表达式
    private String expression;

    @Override
    public Pointcut getPointcut() {
        if (pointcut == null) {
            pointcut = new AspectJExperssionPointcut(expression);
        }
        return pointcut;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }

    @Override
    public Advice getAdvice() {
        return advice;
    }

    public void setAdvice(Advice advice) {
        this.advice = advice;
    }
}
